]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
polkitAgent: Make authenticate button insensitive if password is empty
authorJonas Dreßler <verdre@v0yd.nl>
Mon, 24 Jun 2019 10:36:47 +0000 (12:36 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Tue, 5 Nov 2019 17:52:33 +0000 (18:52 +0100)
According to the mockups, make the polkit dialogs "Authenticate" button
insensitive and don't respond to pressing the enter key if no password
is supplied.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/788

js/ui/components/polkitAgent.js

index 2393eff3e43671cc408f355be29a99b2933e7a45..e304c2a4638f41baf54a971e7db76e504eda4162 100644 (file)
@@ -98,6 +98,9 @@ var AuthenticationDialog = GObject.registerClass({
         });
         ShellEntry.addContextMenu(this._passwordEntry, { isPassword: true });
         this._passwordEntry.clutter_text.connect('activate', this._onEntryActivate.bind(this));
+        this._passwordEntry.bind_property('reactive',
+            this._passwordEntry.clutter_text, 'editable',
+            GObject.BindingFlags.SYNC_CREATE);
         this._passwordBox.add_child(this._passwordEntry);
 
         this._workSpinner = new Animation.Spinner(WORK_SPINNER_ICON_SIZE, true);
@@ -134,7 +137,14 @@ var AuthenticationDialog = GObject.registerClass({
                                               key: Clutter.Escape });
         this._okButton = this.addButton({ label: _("Authenticate"),
                                           action: this._onAuthenticateButtonPressed.bind(this),
-                                          default: true });
+                                          reactive: false });
+        this._okButton.bind_property('reactive',
+            this._okButton, 'can-focus',
+            GObject.BindingFlags.SYNC_CREATE);
+
+        this._passwordEntry.clutter_text.connect('text-changed', text => {
+            this._okButton.reactive = text.get_text().length > 0;
+        });
 
         this._doneEmitted = false;
 
@@ -189,18 +199,15 @@ var AuthenticationDialog = GObject.registerClass({
         }
     }
 
-    _updateSensitivity(sensitive) {
-        this._passwordEntry.reactive = sensitive;
-        this._passwordEntry.clutter_text.editable = sensitive;
-
-        this._okButton.can_focus = sensitive;
-        this._okButton.reactive = sensitive;
-        this._setWorking(!sensitive);
-    }
-
     _onEntryActivate() {
         let response = this._passwordEntry.get_text();
-        this._updateSensitivity(false);
+        if (response.length === 0)
+            return;
+
+        this._passwordEntry.reactive = false;
+        this._okButton.reactive = false;
+        this._setWorking(true);
+
         this._session.response(response);
         // When the user responds, dismiss already shown info and
         // error texts (if any)
@@ -259,7 +266,9 @@ var AuthenticationDialog = GObject.registerClass({
 
         this._passwordBox.show();
         this._passwordEntry.set_text('');
-        this._updateSensitivity(true);
+        this._passwordEntry.reactive  = true;
+        this._okButton.reactive = false;
+        this._setWorking(false);
 
         this._ensureOpen();
         this._passwordEntry.grab_key_focus();